﻿Public Class Frm_Rech_Avoc_Clien

    Private Sub Frm_Rech_Avoc_Clien_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Frm_Avoc_Clien.Enabled = True
        Frm_mohamin_mowakil.Enabled = True
    End Sub

    Private Sub Frm_Rech_Avoc_Clien_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        comb_matorido_elbaht.SelectedIndex = 0
    End Sub


    Private Sub txt_rech_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_rech.TextChanged
        Try
            List_tous.Items.Clear()
            Partager.list_recherch.Clear()
            If comb_matorido_elbaht.SelectedItem = "الرقم المهني" Then

                For Each av As Avocat_partenaire In Partager.moi.List_avoca_partenaire
                    If av.Num_Prof.ToString.Contains(txt_rech.Text) Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.Num_Prof, av.Nom_a, av.Prenom_a}))

                    End If

                Next

            ElseIf comb_matorido_elbaht.SelectedItem = "الاسم العائلي" Then

                For Each av As Avocat_partenaire In Partager.moi.List_avoca_partenaire
                    If av.Nom_a.Contains(txt_rech.Text) Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.Num_Prof, av.Nom_a, av.Prenom_a}))
                    End If

                Next

            ElseIf comb_matorido_elbaht.SelectedItem = "الاسم الشخصي" Then

                For Each av As Avocat_partenaire In Partager.moi.List_avoca_partenaire
                    If av.Prenom_a.Contains(txt_rech.Text) Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.Num_Prof, av.Nom_a, av.Prenom_a}))
                    End If

                Next


            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        If txt_rech.Text = "" Then
            List_tous.Items.Clear()
        End If
    End Sub

    Private Sub Btn_choisi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_choisi.Click

        If List_tous.SelectedIndices.Count > 0 Then

            Dim avo As Avocat_partenaire
            Dim j As Integer = 0
            Try
                For Each i As Integer In List_tous.SelectedIndices
                    avo = Partager.list_recherch(i)
                    For Each khib As Avocat_partenaire In Partager.moi.List_avoca_partenaire
                        If avo.Id = khib.Id Then
                            If Partager.type_rech_mowakil = "Frm_mohamin_mowakil" Then
                                Frm_mohamin_mowakil.Comb_nom.Text = avo.Nom_a & "  " & avo.Prenom_a
                            Else
                                Frm_Avoc_Clien.List_tous.Items(j).Focused = True
                                Frm_Avoc_Clien.List_tous.Items(j).Selected = True
                            End If
                        End If
                        j += 1
                    Next
                Next
                Me.Close()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        Else
            MsgBox("اختر محامي من القائمة", MsgBoxStyle.Information, "خطأ في البحث")
        End If
    End Sub



End Class